<template>
  <div id="app">
    <Topbar :key="topbarKey" />
    <Header />
    <router-view @updateKey="updateKeyFn"/>  
    <Footer />
    <Login  v-show='isShowLoginModal'/>
  <transition name="slide">
      <Toast v-show="isShowToast" />
    </transition>
    <!-- <button @click="fn">获取token</button> -->
    <!-- <button @click="fn">点击{{isShowLoginModal}}</button> -->
  </div>
</template>
<script>
import Topbar from "./components/Topbar.vue"
import Header from "./components/Header.vue"
import Footer from "./components/Footer.vue"
import Login from "./components/Login.vue"
import Toast from "./components/Toast.vue"
// import axios from "axios"
// import request from "@/request/request.js"
import {JingPinAPI} from "@/request/api.js"
import { mapState } from "vuex";
export default {
  data(){
    return{
      topbarKey:0
    }
  },
  components:{
    Topbar,Header,Footer,Login,Toast
  },
   computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
     isShowToast: (state) => state.showToast.isShowToast,
    })
  },
  created(){
    JingPinAPI().then((res)=>{
      console.log("res:",res);
    })  
    // request.get("/products/recommend").then((res)=>{
    //   console.log("res:",res);
    // })
    // axios.get("http://192.168.113.249:8081/cms/products/recommend").then((res)=>{
    //   console.log("res:",res);
    // })
  },
  methods:{
    async fn(){
      let res1 = await JingPinAPI();
      console.log("res1",res1); 
      //  let res2 = await JingPinAPI();
      // console.log("res2",res2); 
      //  let res3 = await JingPinAPI();
      // console.log("res3",res3);
    },
updateKeyFn(){
      this.topbarKey++;
    }
  },
  watch:{
    "$route.path":{
      handler(newVal,oldVal){
        console.log(newVal,oldVal);
        if(oldVal !="/"){
          this.topbarKey++;
        }
      }
    }
  }
}
</script>
<style lang="less">
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.5s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
